/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.actions.interval;

import com.android1.amarena2d.actions.base.IntervalAction;
import com.android1.amarena2d.nodes.behavior.ActionTarget;

public class ScaleTo extends IntervalAction {

    protected float startScaleX;
    protected float startScaleY;
    protected float endScaleX;
    protected float endScaleY;
    protected float deltaX;
    protected float deltaY;


    public static ScaleTo $(float duration, float scalex, float scaley) {
        return new ScaleTo(duration, scalex, scaley);
    }

    public static ScaleTo $(float duration, float scale) {
        return new ScaleTo(duration, scale, scale);
    }

    public ScaleTo(float duration, float scalex, float scaley) {
        super(duration);
        endScaleX = scalex;
        endScaleY = scaley;
    }

    @Override
    public void start(ActionTarget target) {
        super.start(target);
        startScaleX = target.getScaleX();
        startScaleY = target.getScaleY();
        deltaX = endScaleX - startScaleX;
        deltaY = endScaleY - startScaleY;

    }

    @Override
    public IntervalAction reverse() {
        return copy();
    }

    @Override
    public void update(float t) {
        target.setScaleX(startScaleX + deltaX * t);
        target.setScaleY(startScaleY + deltaY * t);
    }


    @Override
    public ScaleTo copy() {
        return ScaleTo.$(duration, endScaleX, endScaleY);
    }


}